import 'package:boss/color_constant.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:hi_common/hi_common.dart';
import 'package:flutter/material.dart';

class ToggleButtonGroup extends StatelessWidget {
  final List<String> children;
  final int selectedIndex;
  final ValueChanged<int> onChanged;

  const ToggleButtonGroup({
    Key key,
    this.children,
    this.selectedIndex = 0,
    this.onChanged,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          border: Border.all(
        color: ColorConstant.ff33,
        width: 1.px,
      )),
      child: Row(
        children: children.map((item) {
          var index = children.indexOf(item);

          return Expanded(
            child: ToggleButton(
              title: item,
              isSelected: index == selectedIndex,
              onTap: () {
                onChanged(index);
              },
            ),
          );
        }).toList(),
      ),
    );
  }
}

class ToggleButton extends StatelessWidget {
  final String title;
  final VoidCallback onTap;
  final bool isSelected;

  const ToggleButton({
    this.title,
    this.onTap,
    this.isSelected = false,
  });

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      behavior: HitTestBehavior.translucent,
      child: Container(
        alignment: Alignment.center,
        height: 70.w,
        child: Text(
          title,
          style: isSelected ? TextStyleConstant().blue_28 : TextStyleConstant().normal_1_28,
        ),
      ),
    );
  }
}
